package com.share.spock.service.impl;

import com.share.spock.model.Address;
import com.share.spock.model.Pay;
import com.share.spock.model.User;
import com.share.spock.model.dto.TestDTO;
import com.share.spock.service.AddressService;
import com.share.spock.service.PayService;
import com.share.spock.service.UserService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author caifan
 * @since 2021/9/22
 * description:
 */
@Service
public class UserServiceImpl implements UserService {

    private final PayService payService;

    private final AddressService addressService;

    public UserServiceImpl(PayService payService, AddressService addressService) {
        this.payService = payService;
        this.addressService = addressService;
    }

    @Override
    public User getUser() {
        User user = new User();
        user.setUserId(111L);
        Address adress = addressService.getAdress();
        user.setArea(adress.getArea());
        Pay pay = payService.getPay();
        user.setTotalPrice(pay.getTotalPrice());
        return user;
    }

    @Override
    public Boolean getUserById(Long userId) {
        Pay pay = payService.getPay();
        List<Address> addressList = addressService.listAddressByUserId(userId);
        User user = new User();
        user.setTotalPrice(pay.getTotalPrice());
        user.setUserId(userId);
        user.setAddressList(addressList);
        return Boolean.TRUE;
    }

    @Override
    public User getUserByIdAndArea(Long userId, String area) {
        Pay pay = payService.getPay();
        TestDTO testDTO = new TestDTO();
        testDTO.setArea("天河");
        testDTO.setCity("广州");
        testDTO.setIdList(Collections.singletonList(2L));
        Address address = addressService.getAddress(userId, testDTO);
        User user = new User();
        user.setTotalPrice(pay.getTotalPrice());
        user.setUserId(userId);
        user.setArea(address.getArea());
        return user;
    }
}
